﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AutoChess
{
   class RendererPool 
    {
        //管理渲染器的池
        /*private List<GridUnitRenderer> gridRenderersPool = new List<GridUnitRenderer>();
        private List<HeroUnitRenderer> heroUnitRenderersPool = new List<HeroUnitRenderer>();*/
        private List<ShipRenderer> shipUnitRenderersPool = new List<ShipRenderer>();

        /*public List<GridUnitRenderer> GridRenderers
        {
            get { return gridRenderersPool; }
        }
        public List<HeroUnitRenderer> HeroRenderers
        {
            get { return heroUnitRenderersPool; }
        }*/
        public List<ShipRenderer> ShipRenderers
        {
            get { return shipUnitRenderersPool; }
        }

        #region hero

        public ShipRenderer GetShipUnitRenderPool(Transform root)
        {
            for (int i = 0; i < shipUnitRenderersPool.Count; i++)
            {
                if (!shipUnitRenderersPool[i].gameObject.activeSelf)
                {
                    //Debug.LogError("从池里获取一个船只渲染器");
                   // shipUnitRenderersPool[i].gameObject.SetActive(true);
                    return shipUnitRenderersPool[i];
                }
            }
            return CreateShipRenderer(root);
        }

        private ShipRenderer CreateShipRenderer(Transform root)
        {
            var ship = new GameObject(GameConst.AC_SHIP);
            ship.transform.Normalize();
            ship.transform.SetParent(root);
            var renderer = ship.AddComponent<ShipRenderer>();
            shipUnitRenderersPool.Add(renderer);
            return renderer;
        }

        /*public HeroUnitRenderer GetHeroUnitRendererPool(Transform root)
        {
            for (int i = 0; i < heroUnitRenderersPool.Count; i++)
            {
                if (!heroUnitRenderersPool[i].gameObject.activeSelf)
                {
                    //Debug.LogError("从池里获取一个英雄渲染器");
                    // heroUnitRenderersPool[i].gameObject.SetActive(true);
                    return heroUnitRenderersPool[i];
                }
            }
            return CreateHeroRenderer(root);
        }
   
        private HeroUnitRenderer CreateHeroRenderer(Transform root)
        {
            var grid = new GameObject(GameConst.AC_HERO);
            grid.transform.Normalize();
            grid.transform.SetParent(root);
            var renderer = grid.AddComponent<HeroUnitRenderer>();
            heroUnitRenderersPool.Add(renderer);
            return renderer;
        }

        public GridUnitRenderer CreateGridRenderer(Transform root)
        {
            var grid = new GameObject(GameConst.AC_GRID);
            grid.transform.Normalize();
            grid.transform.SetParent(root);
            var renderer = grid.AddComponent<GridUnitRenderer>();
            return renderer;
        }*/

        #endregion
    }
}
